<template>
  <div class="home-container">
    <!-- 热门设计 -->
    <div class="top-box">
      <div class="title1">
        <p style="color: #555555; font-size: 32px; font-weight: 700">
          热门设计
        </p>
      </div>
    </div>
    <div class="Carousel">
      <el-carousel :interval="2000" type="card" height="400px" width="400px">
        <el-carousel-item v-for="item in hotList" :key="item.id">
          <img :src="item.url" alt="" class="image" />
        </el-carousel-item>
      </el-carousel>
    </div>
    <!-- 灵感分类 -->
    <div class="top-box">
      <div class="title2">
        <p style="color: #555555; font-size: 32px; font-weight: 700">
          厨房灵感
        </p>
      </div>
    </div>
    <div class="commodity_ul">
      <div
        class="commodity_ul_li"
        v-for="(i, index) in this.commoditylist"
        :key="index"
        @click="router_id(i)"
      >
        <div class="commodity_ul_li_info">
          <div class="img">
            <img :src="'http://127.0.0.1:8000' + i.images[0].image" alt="" />
          </div>
          <div style="display: flex; justify-content: space-between">
            <p>{{ i.big_name }}</p>
            <p>➤</p>
          </div>
        </div>
      </div>
      <el-empty
        v-if="this.Empty"
        description="暂时还没有宝贝哦"
        :image-size="300"
      ></el-empty>
    </div>
    <div style="margin-bottom: 100px"></div>
  </div>
</template>

<script>
import { getinspiration } from "@/api/router.js";
export default {
  data() {
    return {
        Empty: true,
      inspirationId : null,
        // 轮播图
      hotList: [
        { id: 0, url: require("@/assets/imgs/厨房001.png") },
        { id: 1, url: require("@/assets/imgs/厨房002.png") },
        { id: 2, url: require("@/assets/imgs/厨房003.png") },
      ],
    //作品列表
      commoditylist: [],
    };
  },
  computed: {},
  created(){
    this.inspirationId = this.$route.query.inspiration_id;
   
    this.getinspirationlisi();
  },
  methods: {
    // 获取灵感数据
    getinspirationlisi() {

      getinspiration(this.inspirationId).then((res) => {
        this.commoditylist = res;
        if (this.commoditylist.length !== 0) {
          this.Empty = false;
        }
      });
    },
    //   跳转详情页
    router_id(i) {
      this.$router.push({ path: "/itemDetails", query: { id: i.id } });
      console.log(i.id);
    },
  }
};
</script>

<style lang="less" scoped>
.home-container {
  width: 100%;
  height:100%;
  .top-box {
    display: flex;
    justify-content: center;
    align-items: center;
    .title1 {
      margin-top: 5px;
      border-left: 5px solid #f59a23;
      padding-left: 15px;
    }
    .title2 {
      margin-top: 40px;
      border-left: 5px solid #f59a23;
      padding-left: 15px;
    }
  }
  //   轮播图
  .Carousel {
    width: 1500px;
    margin: 0 auto;
    .image {
      margin-top: 40px;
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }
  //  一行放四个，多的数据换行排列
  .commodity_ul {
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
    margin-left: 7%;
    .commodity_ul_li {
      margin-top: 30px;
      .commodity_ul_li_info {
        width: 100%;
        height: 100%;
        margin-right: 20px; /* 每个元素右间距设置为20px */

        /* 计算每个元素的宽度：20px是前三个元素的间距（margin-right）和，除以4即为每个元素的宽度 */

        width: calc((100% + 280%) / 4);
        /* 将下标是4的倍数元素的margin-right设置为0，即将每行最后一个元素的margin-right置0 */

        .commodity_ul_li_info:nth-of-type(4n + 0) {
          margin-right: 0;
        }
        .img {
          width: 400px;
          height: 250px;
          img {
            width: 100%;
            height: 100%;
            object-fit: cover;
          }
        }
        p {
          margin-top: 20px;
          font-size: 18px;
          font-weight: 700;
          color: #333333;
        }
      }
    }
    .el-empty {
      margin: 0 auto;
    }
  }
  .commodity_ul_li .commodity_ul_li_info {
    overflow: hidden; /* 保持盒子大小不变，隐藏超出部分 */
  }

  .commodity_ul_li .img img {
    transition: transform 0.3s ease-in-out;
  }

  .commodity_ul_li .img img:hover {
    transform: scale(1.1); /* 放大图片 */
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    opacity: 0.9;
  }
}
</style>
